﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CPPEI
{
    public class PagedResult<T> : Result
    {
        public int Total { get; private set; }
        public int Start { get; private set; }

        public int Limit { get;  private set; }

        public int Count { get; private set; }

        public List<T> Data { get; private set; }

        /// <summary>
        /// 构建正确的结果
        /// </summary>
        /// <param name="data"></param>
        /// <param name="start"></param>
        /// <param name="limit"></param>
        /// <param name="total"></param>
        public PagedResult(List<T> data, int start, int limit, int total)
            : base()
        {
            Start = start;
            Limit = limit;
            Total = total;

            Data = data;
            IsSuccess = true;
            ErrorCode = CPPEI.ErrorCodes.NoError;
            Message = CPPEI.ErrorCodes.GetMessage(ErrorCode);
        }

        /// <summary>
        /// 构建有错误的结果
        /// </summary>
        /// <param name="errorCode"></param>
        public PagedResult(int errorCode)
        {
            IsSuccess = false;
            ErrorCode = errorCode;
            Message = CPPEI.ErrorCodes.GetMessage(ErrorCode);
        }

        /// <summary>
        /// 构建有错误的结果
        /// </summary>
        /// <param name="errorCode"></param>
        /// <param name="message"></param>
        public PagedResult(int errorCode, string message)
        {
            IsSuccess = true;
            ErrorCode = errorCode;
            Message = message;
        }
    }
}
